package st.business.tepth.business.history;

import java.util.List;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.HistoryConditionBean;
import st.business.tepth.business.bean.HistoryResultBean;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-03-02 15:39
 */

public class HistoryPresenter extends HistoryContract.Presenter {
    private final HistoryContract.View mView;
    private final HistoryContract.Model mModel;

    public HistoryPresenter(HistoryContract.View view) {
        mView = view;
        mModel = new HistoryModel();
    }

    @Override
    void getCondition(String token) {
        addDisposable(mModel.getCondition(token,
                new OnDataConvertListener<HistoryConditionBean>() {
                    @Override
                    public void convert(HistoryConditionBean bean) {
                        if (mView != null) {
                            mView.showCondition(bean);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }

    @Override
    void getHistoryData(final boolean isRefresh, String token, String busNumber,
                        String startDate, String endDate,
                        String classification, String workType,
                        int pageSize, int pageNumber) {
        addDisposable(mModel.getHistoryData(token, busNumber, startDate,
                endDate, classification, workType, pageSize, pageNumber,
                new OnDataConvertListener<List<HistoryResultBean>>() {
                    @Override
                    public void convert(List<HistoryResultBean> list) {
                        if (mView != null) {
                            mView.showHistoryResult(isRefresh,list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(null);
                        }
                    }
                }));
    }
}
